import time

from selenium import webdriver
from selenium.webdriver.common.by import By

# 封装重复部分->函数, 简化代码
def LoginAndCheck(username, password):

    web = webdriver.Edge()
    web.implicitly_wait(5)

    web.get("http://127.0.0.1/mgr/sign.html")
    if username is not None:
      web.find_element(By.ID, "username").send_keys(username)
    if password is not None:
      web.find_element(By.ID, "password").send_keys(password)

    web.find_element(By.CSS_SELECTOR, "button").click()

    time.sleep(2)
    return web.switch_to.alert.text
